//
//  GoodBottomMenuView.m
//  MobileShoppingMall
//
//  Created by 冯传昌 on 2021/4/26.
//  Copyright © 2021 冯传昌. All rights reserved.
//

#import "GoodBottomMenuView.h"


@interface GoodBottomMenuView()

@property (nonatomic,strong) UIView *bgView;

@property (nonatomic,strong) CustomButtonView *storeBtn;//店铺
@property (nonatomic,strong) CustomButtonView *serviceBtn;//客服

@property (nonatomic,strong) UIButton *orderBtn;//立即下单

@property (nonatomic,strong) UILabel *cartNumbLB;//商品数量lb

@end

@implementation GoodBottomMenuView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = UIColor.whiteColor;
        
        [self initUI];
    }
    return self;
}

#pragma mark - setter
- (void)setCartNum:(NSInteger)cartNum{
    _cartNum = cartNum;
    if (_cartNum > 0) {
        _cartNumbLB.hidden = NO;
        _cartNumbLB.text = [NSString stringWithFormat:@"%ld",_cartNum];
    }else{
        _cartNumbLB.hidden = YES;
    }
}

#pragma mark - UI
-(void)initUI{
    UIView *lineV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 2)];
    lineV.backgroundColor = MainBackColor;
    [self addSubview:lineV];
    [self addSubview:self.bgView];
    [self.bgView addSubview:self.storeBtn];
    [self.bgView addSubview:self.serviceBtn];
    [self.bgView addSubview:self.cartBtn];
    [self.bgView addSubview:self.addToCartBtn];
    [self.bgView addSubview:self.orderBtn];
    [self.cartBtn addSubview:self.cartNumbLB];
    
    WEAKSELF(self);
    [self.storeBtn setTouchBlock:^{
        [weakSelf touchStoreClick];
    }];
    [self.serviceBtn setTouchBlock:^{
        [weakSelf touchServiceClick];
    }];
    [self.cartBtn setTouchBlock:^{
        [weakSelf touchShoppingCartClick];
    }];
}

#pragma mark - lazy
- (UIView *)bgView{
    if (!_bgView) {
        _bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 2, ScreenWidth, 58)];
        _bgView.backgroundColor = UIColor.whiteColor;
    }
    return _bgView;
}

- (CustomButtonView *)storeBtn{
    if (!_storeBtn) {
        _storeBtn = [[CustomButtonView alloc] initWithFrame:CGRectMake(20, 9, 40, 40)];
        _storeBtn.image = LoadImage(@"商品详情_店铺");
        _storeBtn.textStr = @"店铺";
    }
    return _storeBtn;
}

- (CustomButtonView *)serviceBtn{
    if (!_serviceBtn) {
        _serviceBtn = [[CustomButtonView alloc] initWithFrame:CGRectMake(self.storeBtn.right + 15, 9, 40, 40)];
        _serviceBtn.image = LoadImage(@"商品详情_客服");
        _serviceBtn.textStr = @"客服";
    }
    return _serviceBtn;
}

- (CustomButtonView *)cartBtn{
    if (!_cartBtn) {
        _cartBtn = [[CustomButtonView alloc] initWithFrame:CGRectMake(self.serviceBtn.right+15, 9, 40, 40)];
        _cartBtn.image = LoadImage(@"商品详情_购物车");
        _cartBtn.textStr = @"购物车";
    }
    return _cartBtn;
}
- (UILabel *)cartNumbLB{
    if (!_cartNumbLB) {
        _cartNumbLB = [[UILabel alloc] initWithFrame:CGRectMake(25, -10, 20, 20)];
        _cartNumbLB.clipsToBounds = YES;
        _cartNumbLB.layer.cornerRadius = _cartNumbLB.width/2;
        _cartNumbLB.font = FontSet(8);
        _cartNumbLB.textAlignment = NSTextAlignmentCenter;
        _cartNumbLB.backgroundColor = RGB(255, 63, 52);
        _cartNumbLB.textColor = UIColor.whiteColor;
        _cartNumbLB.hidden = YES;
    }
    return _cartNumbLB;
}

- (UIButton *)addToCartBtn{
    if (!_addToCartBtn) {
        _addToCartBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _addToCartBtn.frame = CGRectMake(ScreenWidth/2, 12, (ScreenWidth/4)-10, 36);
        _addToCartBtn.clipsToBounds = YES;
        _addToCartBtn.layer.cornerRadius = 18;
        _addToCartBtn.layer.borderWidth = 1;
        _addToCartBtn.layer.borderColor = MainPureColor(190).CGColor;
        [_addToCartBtn setTitle:@"加入购物车" forState:normal];
        [_addToCartBtn.titleLabel setFont:FontSet(13)];
        [_addToCartBtn setTitleColor:MainBlackTextColor forState:normal];
        [_addToCartBtn addTarget:self action:@selector(addCartClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return _addToCartBtn;
}

- (UIButton *)orderBtn{
    if (!_orderBtn) {
        _orderBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _orderBtn.frame = CGRectMake(self.addToCartBtn.right+10, 12, (ScreenWidth/4)-10, 36);
        _orderBtn.clipsToBounds = YES;
        _orderBtn.layer.cornerRadius = 18;
        _orderBtn.backgroundColor = RGB(26, 128, 255);
        [_orderBtn setTitle:@"立即下单" forState:normal];
        [_orderBtn.titleLabel setFont:FontSet(13)];
        [_orderBtn setTitleColor:UIColor.whiteColor forState:normal];
        [_orderBtn addTarget:self action:@selector(orderClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return _orderBtn;
}

#pragma mark - SEL
//商店
-(void)touchStoreClick{
    if (self.touchBlock) {
        self.touchBlock(0);
    }
}
//客服
-(void)touchServiceClick{
    if (self.touchBlock) {
        self.touchBlock(1);
    }
}
//购物车
-(void)touchShoppingCartClick{
    if (self.touchBlock) {
        self.touchBlock(2);
    }
}
//加入购物车
-(void)addCartClick{
    if (self.touchBlock) {
        self.touchBlock(3);
    }
}
//立即下单
-(void)orderClick{
    if (self.touchBlock) {
        self.touchBlock(4);
    }
}

@end
